define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/aftersales/index' + location.search,
                    add_url: 'order/aftersales/add',
                   // edit_url: 'order/aftersales/edit',
                    //del_url: 'order/aftersales/del',
                    multi_url: 'order/aftersales/multi',
                    import_url: 'order/aftersales/import',
                    table: 'order_aftersale',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'aftersale_sn', title: __('Aftersale_sn'), operate: 'LIKE'},
                      //  {field: 'refuse', title: __('Refuse'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'user.nickname', title: __('客户昵称'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('客户手机号'), operate: 'LIKE'},
                        {field: 'refund_fee', title: __('退款金额'), operate:'BETWEEN'},
                       // {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                       // {field: 'reason', title: __('Reason'), operate: 'LIKE'},
                       // {field: 'is_recive', title: __('Is_recive')},
                       // {field: 'is_return', title: __('Is_return')},
                      //  {field: 'refund_reason', title: __('Refund_reason'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                     //   {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                      //  {field: 'order_id', title: __('Order_id')},
                     //   {field: 'order_item_id', title: __('Order_item_id')},
                     //   {field: 'return_time', title: __('Return_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                    //    {field: 'goods_id', title: __('Goods_id')},
                    //    {field: 'goods_sku_text', title: __('Goods_sku_text'), operate: 'LIKE'},
                        {field: 'goods_title', title: __('Goods_title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'goods_image', title: __('Goods_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                    //    {field: 'goods_original_price', title: __('Goods_original_price'), operate:'BETWEEN'},
                     //   {field: 'total_amount', title: __('Total_amount'), operate:'BETWEEN'},
                   //     {field: 'total_fee', title: __('Total_fee'), operate:'BETWEEN'},
                    //    {field: 'pay_price', title: __('Pay_price'), operate:'BETWEEN'},
                     //   {field: 'goods_sn', title: __('Goods_sn'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                    //    {field: 'goods_price', title: __('Goods_price'), operate:'BETWEEN'},
                        {field: 'goods_num', title: __('Goods_num')},
                        {field: 'aftersale_status', title: __('Aftersale_status'), searchList: {"-1":__('Aftersale_status -1'),"0":__('Aftersale_status 0'),"1":__('Aftersale_status 1'),"2":__('Aftersale_status 2')}, formatter: Table.api.formatter.status},
                        {field: 'refund_status', title: __('Refund_status'), searchList: {"-1":__('Refund_status -1'),"0":__('Refund_status 0'),"1":__('Refund_status 1')}, formatter: Table.api.formatter.status},
                    //    {field: 'is_agree', title: __('Is_agree')},
                    //     {field: 'confirm_time', title: __('Confirm_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                    //     {field: 'refund_time', title: __('Refund_time')},
                    //     {field: 'agree_time', title: __('Agree_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                    //     {field: 'refund_fee', title: __('Refund_fee'), operate:'BETWEEN'},
                    //     {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                    //     {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                    //     {field: 'order.order_sn', title: __('Order.order_sn'), operate: 'LIKE'},
                    //     {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                    //     {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                    //     {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                    //     {field: 'item.goods_title', title: __('Item.goods_title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                    //     {field: 'item.goods_image', title: __('Item.goods_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                    //     {field: 'item.goods_original_price', title: __('Item.goods_original_price'), operate:'BETWEEN'},
                    //     {field: 'item.goods_price', title: __('Item.goods_price'), operate:'BETWEEN'},
                    //     {field: 'item.goods_num', title: __('Item.goods_num')},
                    //     {field: 'item.rights_title', title: __('Item.rights_title'), operate: 'LIKE'},
                    //     {field: 'item.rights_card', title: __('Item.rights_card'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                    //     {field: 'item.rights_tags', title: __('Item.rights_tags'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                    //     {field: 'item.rights_num', title: __('Item.rights_num')},
                    //     {field: 'item.used_num', title: __('Item.used_num')},
                    //     {field: 'item.canuse_num', title: __('Item.canuse_num')},
                        {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'send',
                                    text: '',
                                    title:'订单详情',
                                    icon: 'fa fa-eye',
                                    classname: 'btn btn-xs btn-warning btn-dialog chakan',
                                    url: 'order/aftersales/detail'
                                },
                                ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'order/aftersales/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'order/aftersales/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'order/aftersales/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        detail: function(){
            Controller.api.bindevent();
            $(document).on("click", "input[type=radio][name='checkinfo']",
                function(){
                    if($(this).val()==2){
                        $('.refund_reason').removeClass('display');
                    }else{
                        $('.refund_reason').addClass('display');
                    }

                });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
